package edu.cmu.cs.stage3.alice.core.property;

import java.io.IOException;

import edu.cmu.cs.stage3.alice.core.Element;
import edu.cmu.cs.stage3.alice.core.ReferenceGenerator;
import edu.cmu.cs.stage3.alice.core.applet.AppletXmlStruct;
import edu.cmu.cs.stage3.io.DirectoryTreeStorer;

public class ClassProperty extends ObjectProperty {

 public ClassProperty (Element owner, String name, Class defaultValue) {
  super( owner, name, defaultValue, Class.class );
  }

 public Class getClassValue () {
  return (Class)getValue();
  }

 //Rem @Override
 protected void decodeObject (org.w3c.dom.Element node, java.util.Vector referencesToBeResolved) throws java.io.IOException {
  //String text = node.getFirstChild().toString(); //?
  String text = getNodeText( node );
  try {
   set( Class.forName( text ) );
  } catch( ClassNotFoundException cnfe ) {
   throw new RuntimeException( text );
   }
  }

 //Rem @Override
 protected void encodeObject (org.w3c.dom.Document document, org.w3c.dom.Element node, DirectoryTreeStorer storer, edu.cmu.cs.stage3.alice.core.ReferenceGenerator referenceGenerator) throws java.io.IOException {
  node.appendChild( createNodeForString( document, getClassValue().getName() ) );
  }

 //Rem @Override
 protected AppletXmlStruct encodeObjectToXml (ReferenceGenerator referenceGenerator) throws IOException {
  AppletXmlStruct struct = new AppletXmlStruct();
  struct.addElement(getClassValue().getName());
  return struct;
  }

 }
